/**
 * Created with IntelliJ IDEA
 * Description
 * User:user
 * Date:2021-10-12
 * Time:10:35
 */
public class TestDemo {
	//switch语句练习
    public static void main(String[] args) {
        int a = 1;
        switch(a){
            case 1:
                System.out.println(1);
                break;
            case 2:
                System.out.println(2);
                break;
            default:
                System.out.println("输入错误\n");
                break;
        }

    }
    //判断闰年
    public static void main25(String[] args) {
        int year = 2000;
        if((year % 400 ==0) || (year % 4 == 0)&&(year % 100 !=0)){
            System.out.println("是闰年\n");
        }else{
            System.out.println("不是闰年\n");
        }
    }
    public static void main24(String[] args) {
        int num = 10;
        if(num > 0){
            System.out.println("正数");
        }else if(num == 0){
            System.out.println("等于0的数");
        }else{
            System.out.println("负数");
        }
    }
    //判断奇数还是偶数
    public static void main23(String[] args) {
        int n = 10;
        if(n % 2 == 0){
            System.out.println("偶数");
        }else{
            System.out.println("奇数");
        }
    }
    //三目运算符求解最大值
    public static void main22(String[] args) {
        int a = 20;
        int b = 20;
        int max = a > b?a:b;
        System.out.println(max);
    }
    public static void main21(String[] args) {
        System.out.println(10 > 20 && 10 / 0 ==0);//不会报错，短路作用
        System.out.println(10 > 20 || 10 / 0 ==0);//不会报错，短路作用
        System.out.println(10 > 20 & 10 / 0 ==0);
        System.out.println(10 > 20 | 10 / 0 ==0);
    }
    public static void main20(String[] args) {
        int a = 110;
        int b = 20;
        //System.out.println(!a < b);编译报错，后面只能是boolean表达式
        System.out.println(!(a<b));//编译不报错
    }
    public static void main19(String[] args) {
        int a = 110;
        int b = 20;
        int c = 30;
        System.out.println(a < b && b < c);
    }
    public static void main18(String[] args) {
        int a = 1;
        int b = 2;
        System.out.println(a == b); //false
        System.out.println(a != b);//true
        System.out.println(a > b);//false
        System.out.println(a < b);//true
        System.out.println(a >= b);//false
        System.out.println(a <= b);//true
    }
    public static void main17(String[] args) {
        int a = 10;
        ++a;//后置++
        //int b = a++; 11
        //int b = ++a; 10
        System.out.println(a);
    }
    public static void main16(String[] args) {
        short s = 1;
       // s = s + 1;编译会报错，因为转化为int转化为了short
        s +=  1;//帮你进行强制类型转换
        s +=  1;//帮你进行强制类型转换
        System.out.println(s);
    }
    public static void main15(String[] args) {
        int a = 10;
        a += 1;
        a = a + 1;
        System.out.println(a);
    }
    public static void main14(String[] args) {
        int a = 10;
        int b = 3;
        System.out.println(a%b);//1
        System.out.println(11.5%2.0);//1.5
        System.out.println(-10 % -3);//-1
        System.out.println(-10 % 3);//-1
        System.out.println(10 % -3);//1
    }
    public static void main13(String[] args) {
        int a = 1;
        int b = 2;
        System.out.println(a / b);//结果为0
        /*int c = 10;
        int d = 0;
        System.out.println(c/d);  //报错，错误类型为算数异常，除零异常，*/
    }

    public static void main12(String[] args) {
        String s = "10";
        int num = Integer.valueOf(s);
        System.out.println(s);
    }
    public static void main11(String[] args) {
        //int转换为字符串
        int a = 10;
        String str1 = a +"";
        System.out.println(str1);
        String str2 = String.valueOf(a);
        System.out.println(str2);
    }
//    public static void main10(String[] args) {
//        byte a = 1;
//        byte b = 2;
//       // byte c = a + b ;//错误，因为a和b都是一个字节，计算机在处理小于一个自己的数的时候，
//          会把小于四个字节的提升为四个字节再进行运算
//        //byte c = (byte)a+b
//        System.out.println(c);
//    }

//    public static void main9(String[] args) {
//        int a = 10;
//        long b = 20;
//        //int c = a + b;//报错是因为编译器自动进行类型提升，受限会把a提升为long类型，然后和b进行运算，结果为long类型
//        //long c = a + b;
//        long c = (int)(a+b);
//    }
//    public static void main8(String[] args) {
//        byte b = 10;    //-128 --- 127
//        System.out.println(b);
//    }
//    public static void main7(String[] args) {
//        int a = 1;
//        boolean b = (boolean) a;//错误
//        boolean c = true;
//        int d = (int)c;         //错误
//    }
//    public static void main6(String[] args) {
//        int a = 10;
//        long l = 11;    //long b = a; //把小类型给大类型，隐式类型转换
//        a = (int)l;
//
//        double d = a;
//        int c = (int)d;
//
//        float f = a;
//        int c2 = (int)f;
//
//    }
//    public static void main5(String[] args) {
//        int a = 2;     //和下面的a重名了
//        {
//            int a = 1; //此时的a作用域在当前花括号内
//            //a = 1相当于修改值
//        }
//        System.out.println(a);//超出了作用域
//    }
    public static void main4(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("a = " + a + " b = " + b);
        System.out.println("a+b="+(a+b));
        System.out.println(10+""+20);
    }

    public static void main3(String[] args) {
        System.out.println("ab"+"cd");
        String str1 = "ab";
        String str2 = "cd";
        System.out.println(str1+str2);
        System.out.println(10+str1+str2);
        System.out.println(10+20+str1+str2);
        System.out.println(str1+str2+10+20);
        String ret1 = 10+str1+str2;
        String ret2 = 10+20+str1+str2;
        String ret3 = str1+str2+10+20;
        System.out.println(ret1);
        System.out.println(ret2);
        System.out.println(ret3);
    }


    public static void main2(String[] args) {
        String str1 = "abcdef";
        String str2 = "高博";
        String str3 = "\'abcde\'";
        String str4 = "\\abcde\\";

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(str4);

    }
    public static void main1(String[] args) {
        //求余数
        System.out.println(-10 % -3);
        System.out.println(-10 % 3);
        System.out.println(10 % -3);
    }
}
